using System;
using System.Data;
using System.Data.SqlClient;

namespace QUAN_LY_NGAN_HANG_CAU_HOI_TRAC_NGHIEM
{
    public class TaiKhoanDAL
    {
        private Guid _giaoVien;

        public Guid GiaoVien
        {
            get { return _giaoVien; }
            set { _giaoVien = value; }
        }

        private Guid _quyen;

        public Guid Quyen
        {
            get { return _quyen; }
            set { _quyen = value; }
        }

        private string _username;

        public string Username
        {
            get { return _username; }
            set { _username = value; }
        }

        private string _password;

        public string Password
        {
            get { return _password; }
            set { _password = value; }
        }

        public static TaiKhoanDAL LayTaiKhoan_UserName(string usr)
        {
            using(SqlConnection cn = new SqlConnection(Globals.ConnectionString))
            {
                TaiKhoanDAL en = new TaiKhoanDAL();
                SqlCommand cmd = new SqlCommand("uspLayTaiKhoan_UserName", cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@usr", SqlDbType.NVarChar, 50).Value = usr;
                cn.Open();
                IDataReader rd = cmd.ExecuteReader();
                if (rd != null)
                {
                    while (rd.Read())
                    {
                        en.GiaoVien = (Guid) rd["GiaoVien"];
                        en.Password = (string) rd["Password"];
                        en.Quyen = (Guid) rd["Quyen"];
                        en.Username = (string) rd["Username"];
                    }
                }
                return en;
            }
        }
    }
}